package com.gzw.dms.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gzw.dms.R;
import com.gzw.dms.base.BaseActivity;

public class DriverTjSelectActivity extends BaseActivity {
    private Toolbar toolbar;
    private EditText et_num, et_chddh, et_fhkh, et_shkh,et_order_num,et_order_goid;
    private TextView tv_num,tv_chddh,tv_fhkh,tv_shkh;
    private Context mContext;
    private Button btn_select;
    private LinearLayout layout_supplius,layout_order_num,layout_order_goid;
    private Intent mIntent;
    private String fpstste;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_driver_tj_select);

    }

    @Override
    protected void initViews() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        et_num = (EditText) findViewById(R.id.et_select_num);
        et_chddh = (EditText) findViewById(R.id.et_select_chddh);
        et_chddh.setInputType(InputType.TYPE_CLASS_NUMBER);
        et_fhkh = (EditText) findViewById(R.id.et_select_fhkh);
        et_shkh = (EditText) findViewById(R.id.et_select_shku);
        et_order_num = (EditText) findViewById(R.id.et_order_num);
        et_order_goid = (EditText) findViewById(R.id.et_order_goid);
        tv_num = (TextView) findViewById(R.id.tv_select_num);
        tv_chddh = (TextView) findViewById(R.id.tv_select_chddh);
        tv_fhkh = (TextView) findViewById(R.id.tv_select_fhkh);
        tv_shkh = (TextView) findViewById(R.id.tv_select_shku);

        btn_select = (Button) findViewById(R.id.btn_select);
        layout_supplius = (LinearLayout) findViewById(R.id.layout_supplius);
        layout_order_goid = (LinearLayout) findViewById(R.id.layout_order_goid);
        layout_order_num = (LinearLayout) findViewById(R.id.layout_order_num);

    }

    @Override
    protected void initData() {
        mContext = this;
        mIntent = getIntent();
        toolbar.setTitle("条件查询");
        setSupportActionBar(toolbar);
        fpstste = (String)mIntent.getExtras().get("fpstste");
        if (fpstste.equals("0")){
            layout_supplius.setVisibility(View.GONE);
            layout_order_goid.setVisibility(View.GONE);
            layout_order_num.setVisibility(View.GONE);
        }else if (fpstste.equals("2")){
            tv_num.setText("用户名");
            tv_chddh.setText("真实姓名");
            tv_shkh.setText("部门");
            layout_supplius.setVisibility(View.GONE);
            layout_order_goid.setVisibility(View.GONE);
            layout_order_num.setVisibility(View.GONE);

        }
    }

    @Override
    protected void initEvents() {
        toolbar.setNavigationOnClickListener(new myOnClick());
        btn_select.setOnClickListener(new myOnClick());


    }

    class myOnClick implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch (v.getId()) {
                case R.id.btn_select:
                    sendData();
                    break;
                default:
                    finish();
                    break;
            }
        }

        private void sendData() {
            Intent mIntent = new Intent();
            //把返回数据存入Intent
            mIntent.putExtra("driver_name1", et_num.getText().toString());
            mIntent.putExtra("driver_phone1", et_chddh.getText().toString());
            mIntent.putExtra("driver_suppliers1", et_fhkh.getText().toString());
            mIntent.putExtra("driver_address1", et_shkh.getText().toString());
            mIntent.putExtra("shiping_order_num", et_order_num.getText().toString());
            mIntent.putExtra("shiping_order_goid", et_order_goid.getText().toString());
            //设置返回数据
            setResult(2, mIntent);
            finish();
        }
    }
}